<template>
  <a-grid-item :span="{xs: 1, sm: 2, md: 8}">
    <a-collapse :default-active-key="['1']" class="g-collapse">
      <a-collapse-item header="基础信息" key="1">
        <template #extra>
          <a-button-group>
            <a-button type="primary" size="small" @click.stop="edit"  v-auth="['document:waybill:save']" ><icon-edit/>编辑</a-button>
<!--            <a-button type="primary" size="small" @click.stop=""><icon-download/>下载</a-button>-->
            <a-button type="primary" size="small" @click.stop="visible.shipment = true"  v-auth="['document:shipmentContainer:index']"><icon-list/>预配货</a-button>
            <a-popconfirm v-if="record.close == false"
            content="确定配货完成了吗?"
            position="bottom"
            @click.stop=""
            @ok="closeOrder()"
            >
            <a-button type="primary" status="danger" size="small"  v-auth="['document:waybill:closeOrderPass']">完成配货</a-button>
            </a-popconfirm>
            <a-button v-else type="" size="small" >配货结束</a-button>
          </a-button-group>
        </template>

        <ma-info :columns="useWaybill.infoColumns" :data="record" layout="horizontal" size="small" :bordered="false"/>
      </a-collapse-item>
    </a-collapse>
  </a-grid-item>
  <ContainerShipmentList v-model="visible.shipment"/>
  <add-modal-form  @emitClick="resetGetRecord" ref="addModalMormRef"></add-modal-form>
</template>
<script setup>
import {inject, ref} from "vue";
import MaInfo from "@/components/ma-info/index.vue"
import useWaybill from "@/utils/crud/useWaybill.js";
import waybill from "@/api/document/waybill.js";
import ContainerShipmentList from "@/views/document/waybill/ContainerShipmentList.vue";
import AddModalForm from "@/views/document/waybill/components/addModalForm.vue";
import { Message } from '@arco-design/web-vue'
const crudRef = inject('crudRef')
const record = inject('record')
const size = ref('small')
const getRecord = inject('getRecord')
const columnsDist = inject('columnsDist')//全部字典
const addModalMormRef = ref()
const visible = ref({
  shipment: false,
})
//重新加载
const resetGetRecord=(e)=>{
    getRecord()
  }
// const edit = ()=>crudRef.value.crudFormRef.edit(record.value)
const edit=()=>{
  console.log('jjjjjjjjj',addModalMormRef.value)
  addModalMormRef.value.onShow(record.value)
}
const closeOrder = async ()=>{
  const res = await waybill.closeOrderPass({id:record.value.id})
  if(res.success){
    record.value.close = true
    Message.success(res.message)
  }else{
    Message.error(res.message)
  }
}
</script>